const arrayToObject = (arr, floor = 0) => {
    const obj = {}
    console.log('floor', floor);
    for (const key in arr) {
        if (Object.hasOwnProperty.call(arr, key)) {
            const item = arr[key];
            if (Array.isArray(item) && floor !== 1) {
                obj[key] = arrayToObject(item, floor--)
            } else {
                obj[key] = item
            }
        }
    }
    return obj
}

const testArr = [
    '1', 
    [
        '2-1', 
        '2-2'
    ], 
    '3', 
    [
        '4-1', 
        [
            '4-2-1', 
            [
                [
                    '4-2-2-1-1', 
                    '4-2-2-1-2'
                ], 
                '4-2-2-2'
            ], 
            '4-2-3'
        ]
    ]
]

const obj = arrayToObject(testArr, 2)
console.log('obj:', obj);